using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TEngine;
using UnityEngine.UI;

namespace GameLogic
{
    public class CellCtrl_ZeroSum : CellCtrl
    {
        public enum CellState
        {
            Normal,    // 正常状态
            Selected,  // 选择状态
            Hint       // 提示状态
        }

        public int Value => _value; // 公开访问属性

        [SerializeField]
        private CellState _currentState = CellState.Normal;

        /// <summary>
        /// 初始化单元格数值（需要在创建时调用）
        /// </summary>
        public void InitializeValue(int value)
        {
            _value = value;
            // 这里可以添加数值显示逻辑，例如更新Text组件
            GetComponentInChildren<Text>().text = value.ToString();
        }
        [SerializeField] private Color normalColor = Color.white;
        [SerializeField] private Color selectedColor = Color.yellow;
        [SerializeField] private Color hintColor = Color.cyan;

        private Image m_imgBg;
        private Text m_txtValue;

        private int _value;


        public override void InitCell(Vector2Int pos, RectTransform rectParent)
        {
            base.InitCell(pos, rectParent);
            m_imgBg = transform.FindChildComponent<Image>("m_imgBg");
            m_txtValue = transform.FindChildComponent<Text>("m_txtValue");
            m_txtValue.text = _value.ToString();
        }


        /// <summary>
        /// 设置单元格状态（增加消除状态处理）
        /// </summary>
        public void SetCellState(CellState state)
        {
            if (_currentState == state) return;
            _currentState = state;
            UpdateVisual();
        }

        private void UpdateVisual()
        {

            m_imgBg.color = _currentState switch
            {
                CellState.Normal => normalColor,
                CellState.Selected => selectedColor,
                CellState.Hint => hintColor,
                _ => normalColor
            };
        }


        /// <summary>
        /// 获取当前状态
        /// </summary>
        public CellState GetCurrentState() => _currentState;
    }
}
